home *** CD-ROM | disk | FTP | other *** search
/ NOVA - For the NeXT Workstation / NOVA - For the NeXT Workstation.iso / Documents / NeXTAnswers / sound.738 < prev    next >
Text File  |  1992-02-06  |  3KB  |  80 lines

  1. {\rtf0\ansi{\fonttbl\f0\fnil Times-Roman;\f1\fmodern Courier;\f2\fswiss Helvetica;}
  2. \paperw11960
  3. \paperh10820
  4. \margl120
  5. \margr120
  6. {\colortbl\red0\green0\blue0;}
  7. \pard\tx960\tx1920\tx2880\tx3840\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600\f0\b0\i0\ul0\fs28 sound archiving bug\
  8. \
  9. Q:  
  10. \pard\tx1140\tx2300\tx3440\tx4600\tx5760\tx6900\tx8060\tx9200\tx10360\tx11520\fc0 I'm having some trouble unarchiving a list of objects which
  11. \pard\tx960\tx1920\tx2880\tx3840\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600\fc0  
  12. \pard\tx1140\tx2300\tx3440\tx4600\tx5760\tx6900\tx8060\tx9200\tx10360\tx11520\fc0 contain sounds.  More specifically, I have a subclass of Text
  13. \pard\tx960\tx1920\tx2880\tx3840\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600\fc0 , 
  14. \pard\tx1140\tx2300\tx3440\tx4600\tx5760\tx6900\tx8060\tx9200\tx10360\tx11520\fc0 called 
  15. \f1\fs24 SoundText
  16. \f0\fs28 , which has an instance variable for an associated sound.  I store a collection of 
  17. \f1\fs24 SoundText
  18. \f0\fs28  objects  in 
  19. \pard\tx960\tx1920\tx2880\tx3840\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600\fc0 a List
  20. \pard\tx1140\tx2300\tx3440\tx4600\tx5760\tx6900\tx8060\tx9200\tx10360\tx11520\fc0  object. 
  21. \pard\tx960\tx1920\tx2880\tx3840\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600\fc0 When unarchiving and playing the sounds back, 
  22. \pard\tx1140\tx2300\tx3440\tx4600\tx5760\tx6900\tx8060\tx9200\tx10360\tx11520\fc0  the sounds
  23. \pard\tx960\tx1920\tx2880\tx3840\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600\fc0  
  24. \pard\tx1140\tx2300\tx3440\tx4600\tx5760\tx6900\tx8060\tx9200\tx10360\tx11520\fc0 can be heard, but they all end with a large crack.  When displayed in a sound view, there is a big drop in the waveform at the end of the data. What's going on here?\
  25. \
  26.  
  27. \pard\tx960\tx1920\tx2880\tx3840\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600 A:  There is a bug in the SoundKit with archiving sounds. The Sound object writes too few bytes to the stream when a sound is recorded and archived. When the sound is unarchived, these bytes appear as zero (which gives you a big crack in a mulaw codec sound).\
  28. The following code snippet provides a work-around:\
  29. \
  30.  
  31. \pard\tx660\tx1320\tx2000\tx2660\tx3320\tx4000\tx4660\tx5320\tx6000\tx6660\f1\fs24\fc0 /*\
  32.  * Sound archive bug writes too few samples, which end up as zeros\
  33.  * when you restore. Work around this by deleting the zero samples.\
  34.  * You lose about 1/50th second of the original sound.\
  35.  */\
  36. static void fixSoundArchiveBug(id aSound)\
  37. \{\
  38.    SNDSoundStruct *soundStruct = [aSound soundStruct];\
  39.    int headerSize = soundStruct->dataLocation;\
  40.  \
  41.    [aSound deleteSamplesAt:[aSound dataSize] - headerSize count:headerSize];\
  42. \}\
  43. \
  44. /*\
  45.  * When unarchiving the list of sound text objects, make sure that the zero\
  46.  * samples are deleted for each sound retrieved.\
  47.  * Note: getSound is a method which returns the sound instance variable in\
  48.  * the SoundText object.\
  49.  */\
  50.   \
  51. - getSoundList:sender\
  52. \{\
  53.    OpenPanel *openPanel;\
  54.    NXTypedStream *typedStream;\
  55.    int i;\
  56.  \
  57.    openPanel = [OpenPanel new];\
  58.    [openPanel runModal];\
  59. \
  60.    typedStream = NXOpenTypedStreamForFile([openPanel filename],NX_READONLY);\
  61.  \
  62.    soundTextList = NXReadObject(typedStream);\
  63.  \
  64.    /* bug fix */\
  65.    for (i = 0; i < [soundTextList count]; i++)\
  66.        fixSoundArchiveBug([[soundTextList objectAt:i] getSound]);\
  67.      \
  68.    NXCloseTypedStream(typedStream);\
  69.    return self;\
  70. \}\
  71. \
  72.  
  73. \pard\tx960\tx1920\tx2880\tx3840\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600\f0\fs28 \
  74.  
  75. \fc0 QA738\
  76. \
  77. Valid for 2.0\
  78. \
  79.  
  80.